apiready = function () {
  api.parseTapmode();
  FastClick.attach(document.body);
  var header = $api.byId('aui-header');
  $api.fixStatusBar(header);
  var pageUpdateUser = new Vue({
      el: '#pageFNScanner',
      data: {
        user_info:{},
        lightOn:'off',
      },
      created: function() {
        var that = this;
        var FNScanner = api.require('FNScanner');
        var y = $("#aui-header").height();
        FNScanner.openView({
            rect:{
                    x: 0,   //（可选项）数字类型；模块左上角的 x 坐标（相对于所属的 Window 或 Frame）；默认：0
                    y: y,   //（可选项）数字类型；模块左上角的 y 坐标（相对于所属的 Window 或 Frame）；默认：0
                    w: api.winWidth, //（可选项）数字类型；模块的宽度；默认：所属的 Window 或 Frame 的宽度
                    h: api.winHeight-y  //（可选项）数字类型；模块的高度；默认：所属的 Window 或 Frame 的高度
                },
            autorotation: true
        }, function(ret, err) {
            app.log("ret",ret);
            if (ret) {
                // app.log("FNScanner openView",ret);
                that.dosomething(ret.content);
            } else {
                alert(JSON.stringify(err));
            }
        });
      },
     methods: {
            switchLight:function(){
               this.lightOn=this.lightOn=='on'?'off':'on';
                var FNScanner = api.require('FNScanner');
                FNScanner.switchLight({
                  status: this.lightOn
                });
            },

            dosomething:function(content){
                  if(!content){
                    return ;
                  }
                 var type = api.pageParam.type;
                 if(type=="payScan"){
                   this.payScan(content);
                 }

                  app.log("FNScanner dosomething",content);
                  // var FNScanner = api.require('FNScanner');
                  // FNScanner.closeView();
                  // closeFrame();
            },
            // 扫码收款
            payScan:function(authCode){
              var total_fee = api.pageParam.total_fee;
              var body = api.pageParam.body;
              app.get("/apiv2/pay/scan",{
                total_fee:total_fee,
                body:body,
                AuthCode:authCode
              },function(res){
                app.log("payScan res",res);
                if(res.code!=200){
                  alert(res.msg);
                  return ;
                }
                alert(res.msg);
                var FNScanner = api.require('FNScanner');
                FNScanner.closeView();
                closeFrame();
              })

            },

            decodeImg:function(){
              var that = this;
              api.getPicture({
                  sourceType: 'album',
                  encodingType: 'jpg',
                  mediaValue: 'pic',
                  destinationType: 'url',
                  allowEdit: true,
                  quality: 50,
                  targetWidth: 100,
                  targetHeight: 100,
                  saveToPhotoAlbum: false
              }, function(ret, err) {
                  if (ret) {

                    var FNScanner = api.require('FNScanner');
                      FNScanner.decodeImg({
                          path: ret.data
                      }, function(ret, err) {
                          if (ret.status) {

                            that.dosomething(ret.content);
                          } else {
                              alert(JSON.stringify(err));
                          }
                      });
                  } else {
                      alert(JSON.stringify(err));
                  }
              });

            },

     }
  })
}
